<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>remanage</title>
    <link rel="stylesheet" href="http://at.alicdn.com/t/c/font_3911564_ynvs5zhem7p.css">
    <link rel="stylesheet" href="../Css/contractList.css">
    <link rel="stylesheet" href="../bsp/css/bootstrap.css">
    <link rel="stylesheet" href="../Css/btn.css">

</head>


<body>
    <div class="rightmain1">
        <div>
            <div>回款管理</div>
            <div>
                <button class="btn1"><span class="iconfont icon-export"></span>导出</button>
                <button class="btn1"><a href="../refund/reManage.html"><span
                            class="iconfont icon-shuaxin"></span>刷新</a></button>
            </div>
        </div>
    </div>

    <div class="rightmain2">
        <div class="shaixuanList">
            <div><span class="iconfont icon-sousuoxiao"></span><span>筛选查询</span></div>
            <form action="" method="post">
                <div>
                    <div><span class="ispanWidth">流水号：</span><input type="text"></div>
                    <div><span class="ispanWidth">合同编号：</span><input type="text"></div>

                    <div>
                        <span class="ispanWidth">客户名称：</span>
                        <input type="text" value="" id="Client_name1" data-toggle="modal" data-target="#myModal">
                        <Span class="iconfont icon-sousuoxiao spanwz"></Span>
                        <!-- Modal -->
                        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                            <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal"
                                            aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                        <h4 class="modal-title" id="myModalLabel">客户选框</h4>
                                    </div>
                                    <div class="modal-body">
                                        <table>
                                            <div>
                                                <select name="hetongbianhao" id="">
                                                    <option></option>
                                                </select>
                                                <input type="text" placeholder="请输入内容">
                                                <button type="button">查询</button>
                                                <button type="reset">重置</button>
                                            </div>
                                            <thead>
                                                <tr>
                                                    <th>客户名称</th>
                                                    <th>客户标签</th>
                                                    <th>客户类型</th>
                                                    <th>主要联系人</th>
                                                    <th>手机号码</th>
                                                </tr>
                                            </thead>
                                            <tbody class="DataShow1"></tbody>
                                        </table>
                                        <!-- 分页 -->
                                        <div class="modal-navigation"></div>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn1 btn-default" data-dismiss="modal">关闭</button>
                                        <button type="button" class="btn1 btn-default" data-dismiss="modal">确定</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div>
                    <div>
                        <span class="ispanWidth">状态：</span>
                        <select name="" id="">
                            <option selected="selected" value="0">--请选择状态--</option>
                            <option>已保存</option>
                            <option>已审核</option>
                            <option>待审核</option>
                            <option>已驳回</option>
                        </select>
                    </div>
                    <div class="rili">
                        <span class="ispanWidth">回款日期：</span>
                        <div><input type="text"><span class="iconfont icon-sousuoxiao spanjz1"></span></div>
                        <button class="btn1">查询</button>
                        <button class="btn1">重置</button>
                    </div>
                </div>
            </form>
        </div>
        <div class="dataList">
            <div>
                <div><span class="iconfont icon-liebiao"></span><span>数据列表</span></div>
                <button class="btn1"><a href="../refund/addRefund.html">新增</a></button>
            </div>
            <table id="table0">
                <thead>
                    <tr>
                        <th>序号</th>
                        <th>流水号</th>
                        <th>客户名称</th>
                        <th>回款日期</th>
                        <th>合同编号</th>
                        <th>回款期次</th>
                        <th>回款金额（万元）</th>
                        <th>是否逾期（万元）</th>
                        <th>状态</th>
                        <th>创建时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody class="DataShow" id="DataShow0"></tbody>
            </table>
        </div>
        <nav aria-label="Page navigation">
            <ul class="pagination" id="pagination0"></ul>
        </nav>

    </div>

    <script src="../js/jquery-3.6.3.js"></script>
    <script src="../bsp/js/bootstrap.js"></script>
    <script src="../js/database.js"></script>
    <script src="../js/contractManage.js"></script>
    <script>
        var idtzm;

        $(document).ready(function () {
            displayContractData2();
            displaytableDatakh();
            delContractData(); //添加删除事件
            addContractDataTZ();
            modifyContractDataTZ();
            ViewContractDataTZ();
            hqidr();

            for (let key in db) {
                localStorage.setItem(key, JSON.stringify(db[key]))
            }
        })


        // //显示合同数据
        // function displayContractData() {
        //     $(".DataShow").html('');
        //     // 文档碎片
        //     let fragment1 = document.createDocumentFragment();
        //     for (let i = 0; i < db.contract.length; i++) {
        //         // console.log(db.contract[0]);
        //         let tr = document.createElement("tr");
        //         if (db.contract[i].contract_state == "已保存" || db.contract[i].contract_state == "已驳回" || db.contract[i].contract_state == "") {
        //             tr.innerHTML = `
        //             <td>${i + 1}</td>
        //             <td>${db.contract[i].contract_number}</td>
        //             <td>${db.contract[i].contract_name}</td>
        //             <td>${db.contract[i].Client_name}</td>
        //             <td>${db.contract[i].contract_day}</td>
        //             <td>${db.contract[i].contract_amount}</td>
        //             <td>${db.contract[i].payment_amount}</td>
        //             <td>${db.contract[i].contract_state}</td>
        //             <td>${db.contract[i].contract_createdDate}</td>
        //             <td>
        //                 <button class="btnModify1 btn1" name="change" data-index='${db.contract[i].id}'>编辑</button>
        //                 <button class="btnView1 btn1" name="ck" data-index='${db.contract[i].id}'>查看</button>
        //                 <button class="btnDelete1 btn1" name="del" data-index='${db.contract[i].id}'>删除</button>
        //             </td>
        //                  `;

        //             fragment1.appendChild(tr);
        //         }
        //         else if (db.contract[i].contract_state == "待审核" || db.contract[i].contract_state == "已审核") {
        //             tr.innerHTML = `
        //             <td>${i + 1}</td>
        //             <td>${db.contract[i].contract_number}</td>
        //             <td>${db.contract[i].contract_name}</td>
        //             <td>${db.contract[i].Client_name}</td>
        //             <td>${db.contract[i].contract_day}</td>
        //             <td>${db.contract[i].contract_amount}</td>
        //             <td>${db.contract[i].payment_amount}</td>
        //             <td>${db.contract[i].contract_state}</td>
        //             <td>${db.contract[i].contract_createdDate}</td>
        //             <td>
        //                 <button class="btnView1 btn1" data-index='${db.contract[i].id}'>查看</button>
        //             </td>
        //                  `;

        //             fragment1.appendChild(tr);
        //         }
        //         else {
        //             tr.innerHTML = `
        //             <td>${i + 1}</td>
        //             <td>${db.contract[i].contract_number}</td>
        //             <td>${db.contract[i].contract_name}</td>
        //             <td>${db.contract[i].Client_name}</td>
        //             <td>${db.contract[i].contract_day}</td>
        //             <td>${db.contract[i].contract_amount}</td>
        //             <td>${db.contract[i].payment_amount}</td>
        //             <td>${db.contract[i].contract_state}</td>
        //             <td>${db.contract[i].contract_createdDate}</td>
        //             <td>
        //                 <button class="btnModify1 btn1" data-index='${db.contract[i].id}'>编辑</button>
        //                 <button class="btnView1 btn1" data-index='${db.contract[i].id}'>查看</button>
        //                 <button class="btnDelete1 btn1" data-index='${db.contract[i].id}'>删除</button>
        //             </td>
        //                 `;

        //             fragment1.appendChild(tr);
        //         }

        //     }

        //     $(".DataShow").append(fragment1);

        // }




        //motaikuang
        function displaytableDatakh() {

            $("DataShow1").html('');
            // 文档碎片
            let fragment1 = document.createDocumentFragment();
            for (let i = 0; i < db.connection.length; i++) {
                // console.log(db.contract[0]);
                let tr = document.createElement("tr");

                tr.innerHTML = `
                <td data-id=${db.connection[i].id} class="djuanze">${db.connection[i].name}</td>
                <td>${db.connection[i].customer_label}</td>
                <td>${db.connection[i].type}</td>
                <td>${db.connection[i].linkman}</td>
                <td>${db.connection[i].phone_number}</td>
             `;

                fragment1.appendChild(tr);

            }

            $(".DataShow1").append(fragment1);

        }


        var cmval;
        var idd;
        function hqidr() {
            let cn;
            $(".DataShow1").on("click", ".djuanze", function (e) {
                idd = Number($(e.target).attr("data-id"));
                // console.log(idd);
                cn = db.connection[idd - 1].name;
                $("#Client_name1").val(cn);
                cmval = $("#Client_name1").val();

            });
        }



        //删除数据
        function delContractData() {
            $("#DataShow0").on("click", ".btnDelete1", function (e) {
                let id = $(e.target).attr("data-index");
                delContractbyid(id);
            })
        }


        //新增数据
        function addContractDataTZ() {
            $(".btnAddData").click(function () {
                window.location = "../refund/addRefund.html";
            });
        }

        //修改
        function modifyContractDataTZ() {
            $("#DataShow0").on("click", ".btnModify1", function (e) {
                idtzm = Number($(e.target).attr("data-index"));
                // window.location.href = encodeURI('./02.html?idtzm')
                let url = "../refund/refundModify.html";
                $("body").load(url);
                // return idtzm;
            });
        }

        //查询
        function ViewContractDataTZ() {
            $("#DataShow0").on("click", ".btnView1", function (e) {
                idtzm = Number($(e.target).attr("data-index"));
                // console.log(idtzm1);
                let url = "../refund/refundDetails.html";
                $("body").load(url);

            })
        }
    </script>

</body>

</html>